import CryptoJS from 'crypto-js'
/**
 * @description: 获取canvas指纹
 */
const hex_md5 = (str) => {
    return CryptoJS.MD5(str).toString()
}

const getCanvasData = () => {
    const canvas = document.createElement('canvas')
    const ctx = canvas.getContext('2d')
    const txt = 'quarkzhong'
    ctx.textBaseline = 'top'
    ctx.font = '14px "Arial"'
    ctx.textBaseline = 'alphabetic'
    ctx.fillStyle = '#f60'
    ctx.fillRect(125, 1, 62, 20)
    ctx.fillStyle = '#069'
    ctx.fillText(txt, 2, 15)
    ctx.fillStyle = 'rgba(102, 204, 0, 0.7)'
    ctx.fillText(txt, 4, 17)
    return canvas.toDataURL()
}

const canvasData = getCanvasData()
const md5 = hex_md5(canvasData)
export default md5
